package org.example.atry.pqdao;

import jakarta.servlet.annotation.WebServlet;
import org.example.atry.dbutil.Dbutil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class xiudao {


    public int add(String name, String charst) {
        Connection conn = Dbutil.getCon();

        String sql = "insert into result(name,charst) values(?,?)";
        try {
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, name);
            ps.setString(2, charst);
            int cs = ps.executeUpdate();
            System.out.println(cs);
            return cs;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            Dbutil.closeConn();
        }
    }

    public Integer delete(String name) {
        Connection conn = Dbutil.getCon();
        try {
            String as = "delete from result where name= ?";
            PreparedStatement ps = conn.prepareStatement(as);
                ps.setString(1,name);
            int cs = ps.executeUpdate();
            return cs;
        }catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            Dbutil.closeConn();
        }
    }
}
